package practite.Demo;

import jdk.nashorn.internal.objects.annotations.Function;

import java.util.Scanner;

public class demo9 {
    //计算器主体
    public static void main(String[] args) {
        for (int i = 0; i < 1; i++) {
            System.out.println("请输入你想要的功能1.加法2.减法3.乘法4.除法5.退出");
            int numfunction = intsc();
            if (numfunction<6&&numfunction>0) {
                switch (numfunction) {
                    case 1:
                        add();
                        i = reload(i);
                        break;
                    case 2:
                        minus();
                        i = reload(i);
                        break;
                    case 3:
                        multiplication();
                        i = reload(i);
                        break;
                    case 4:
                        division();
                        i = reload(i);
                        break;
                    case 5:
                        i = 100;
                        break;
                }
            }else {
                System.out.println("输入错误请重新输入！！");
                i = -1;
            }
        }
        System.out.println("感谢使用望舒计算器");
    }
    //加法
    public static void add(){
        System.out.println("请输入数字1与数字2");
        int num1 = intsc();
        int num2 = intsc();
        int sum = num1 + num2;
        System.out.println("结果为"+sum);
    }
    //减法
    public static void minus(){
        System.out.println("请输入数字1与数字2");
        int num1 = intsc();
        int num2 = intsc();
        int minus = num1 - num2;
        System.out.println("结果为"+minus);
    }
    //乘法
    public static void multiplication(){
        System.out.println("请输入数字1与数字2");
        int num1 = intsc();
        int num2 = intsc();
        int sum = num1 * num2;
        System.out.println("结果为"+sum);
    }
    //除法
    public static void division(){
        System.out.println("请输入数字1与数字2");
        int num1 = intsc();
        int num2 = intsc();
        int sum = num1 / num2;
        int surplus = num1 % num2;
        System.out.println("结果为"+sum+"\t余数为"+surplus);
    }
    //重新加载
    public static int reload(int i){
        for (int j = 0; j < 1; j++) {
            System.out.println("是否重新使用计算器重新请按1结束请按2");
            int a = intsc();
            if (a!=1&&a!=2){
                System.out.println("输入错误请重新输入");
                j = -1;
            }else {
                if (a==1){
                    i = -1;
                }else {
                    i = 100;
                }
            }
        }
        return i;
    }
    //输入int形
    public static int intsc(){
        Scanner sc =  new Scanner(System.in);
        int a = sc.nextInt();
        return a;
    }
}
